package api

import (
	"fmt"
	"gameserver/core"
	"gameserver/pb"

	"github.com/aceld/zinx/ziface"
	"github.com/aceld/zinx/znet"
	"github.com/golang/protobuf/proto"
)

type AnimationApi struct {
	znet.BaseRouter
}

func (*AnimationApi) Handle(request ziface.IRequest) {
	msg := &pb.AnimaClip{}
	err := proto.Unmarshal(request.GetData(), msg)
	fmt.Println("====", msg.AnimaName)

	if err != nil {
		fmt.Println("Move: Position Unmarshal error ", err)
		return
	}
	pID, err := request.GetConnection().GetProperty("pID")
	if err != nil {
		fmt.Println("GetProperty pID error", err)
		request.GetConnection().Stop()
		return
	}

	player := core.WorldMgrObj.GetPlayerByPID(pID.(int32))

	//4. 让player对象发起动画信息广播
	player.UpdateAnima(msg.AnimaName)
}
